package main

import (
	"bytes"
	"io"
	"net/http"
)

type HttpClient struct {
	Url     string
	Data    []byte
	Headers map[string]string
	Callbak func(int, []byte)
}

func (hc *HttpClient) Post() error {

	req, err := http.NewRequest("POST", hc.Url, bytes.NewBuffer(hc.Data))
	if err != nil {
		return err
	}

	for k, v := range hc.Headers {
		req.Header.Add(k, v)
	}

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	body, err := io.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	hc.Callbak(resp.StatusCode, body)
	return nil
}
